def gr():
    n = 17;
    dist = [
        633, 257,  91, 412, 150,  80, 134, 259, 505, 353, 324,  70, 211, 268, 246, 121, 390,
        661, 227, 488, 572, 530, 555, 289, 282, 638, 567, 466, 420, 745, 518, 228, 169, 112,
        196, 154, 372, 262, 110, 437, 191,  74,  53, 472, 142, 383, 120,  77, 105, 175, 476,
        324, 240,  27, 182, 239, 237,  84, 267, 351, 309, 338, 196,  61, 421, 346, 243, 199,
        528, 297,  63,  34, 264, 360, 208, 329,  83, 105, 123, 364,  35,  29, 232, 444, 292,
        297,  47, 150, 207, 332,  29, 249, 402, 250, 314,  68, 108, 165, 349,  36, 495, 352,
         95, 189, 326, 383, 202, 236, 154, 578, 439, 336, 240, 685, 390, 435, 287, 184, 140,
        542, 238, 254, 391, 448, 157, 301, 145, 202, 289,  55,  57, 426,  96, 483, 153, 336
    ];
    return n, dist

def berlin():
    '''
    sample from CPLEX
    '''
    n = 52;
    dist = [
         666,  281,  396,  291,  326,  641,  427,  600,  561, 1041,  655,  975, 1121,  299,  260,
         430,  162,  305,  210,  287,   46,  181,  275,  410,  729,  799,  707,  406,  360,  146,
          91,  827,  135,  122,  125,  208,  240,  166,  209,  395,  566,  464,  154,  240,  280,
         791,  267,   64,  217,  789, 1220,  649, 1047,  945,  978,   45,  956, 1135, 1133, 1639,
        1259, 1440, 1516,  958,  724,  495,  595,  843,  564,  392,  636,  510,  922, 1029, 1192,
        1302, 1244,  635,  390,  541,  730, 1489,  782,  777,  785,  858,  897,  828,  870,  896,
         103, 1124,  745,  823,  859, 1151,  910,  728,  596, 1422, 1716,  604,  509,  543,  611,
         308,  486,  487, 1267,  891, 1248, 1400,  505,  537,  217,  135,  207,  441,  289,  241,
         361,  506,  653, 1006, 1068,  970,  651,  504,  209,  245,  903,  394,  374,  368,  447,
         462,  392,  427,  247,  550,  557,  434,  220,  553, 1072,  505,  288,  463,  995, 1484,
         104,   70, 1026,  525,  611,  534,  663,  294,  711,  897,  100,  384,  800,  532,  475,
         501,  681,  437,  538,  125,  109,  516,  527,  417,  580,  690,  541,  371,  517,  267,
         275,  271,  190,  155,  230,  188,  545,  950,  245,  307,  411,  231,  660,  137,  345,
         478,  397,  909,   35,  924,  471,  584,  513,  761,  382,  769,  944,   25,  309,  700,
         430,  401,  407,  577,  332,  437,   32,  150,  552,  584,  479,  510,  594,  437,  270,
         590,  163,  171,  166,   87,   51,  127,   85,  480,  848,  267,  212,  331,  171,  674,
          47,  242,  387,  500,  984,  957,  492,  596,  523,  726,  349,  744,  923,   40,  329,
         735,  466,  428,  435,  612,  368,  469,   57,  124,  533,  559,  452,  528,  624,  472,
         305,  568,  197,  206,  201,  121,   86,  162,  120,  504,  881,  260,  241,  360,  182,
         662,   71,  277,  414,  465,  955,  918, 1096, 1096, 1627, 1245, 1440, 1522,  935,  714,
         451,  562,  807,  552,  362,  609,  491,  901, 1012, 1190, 1298, 1237,  637,  386,  512,
         701, 1460,  760,  754,  762,  836,  875,  804,  847,  858,   76, 1095,  727,  789,  844,
        1157,  890,  702,  585, 1405, 1715,  183,  180, 1145,  812, 1234, 1414,  453,  661,  507,
         381,  126,  636,  580,  415,  587,  487,  616, 1023, 1049,  941,  831,  759,  457,  339,
         645,  455,  435,  422,  461,  446,  414,  422,   64,  856,  359,  530,  187,  599, 1136,
         495,  383,  644,  860, 1430,   83, 1166,  874, 1317, 1507,  561,  818,  670,  565,  308,
         810,  763,  593,  767,  606,  714, 1126, 1135, 1024,  998,  940,  640,  510,  570,  607,
         589,  575,  596,  572,  558,  555,  239, 1036,  390,  686,  361,  734, 1257,  618,  551,
         815,  883, 1487, 1083,  792, 1237, 1428,  490,  764,  686,  548,  291,  770,  751,  560,
         735,  538,  639, 1050, 1055,  945,  950,  912,  619,  471,  501,  552,  536,  521,  534,
         506,  500,  492,  244, 1032,  308,  632,  329,  670, 1185,  550,  507,  772,  800, 1404,
         387,  443,  620,  762,  915, 1461, 1190, 1124, 1076, 1314, 1086, 1144,  770,  631,  541,
         417,  418, 1042, 1251, 1187, 1031,  706,  906,  920,  920,  835,  810,  885,  846, 1180,
        1552,  789,  913, 1068,  787,  705,  775, 1000, 1043,  285,  399,  452,  653,  388,  538,
        1078,  807,  769,  694,  927,  700,  758,  388,  245,  335,  283,  182,  688,  875,  800,
         651,  584,  520,  535,  536,  451,  430,  503,  465,  836, 1170,  484,  526,  705,  401,
         517,  391,  617,  663,  188,  619,  206,  784,  759, 1400, 1137, 1169,  920, 1195, 1020,
        1008,  760,  620,  254,  185,  294,  805, 1056, 1104, 1004, 1010,  854,  874,  881,  807,
         804,  863,  836, 1248, 1371,  931,  822, 1098,  696,  324,  756,  959,  885,  540,  279,
         962,  884, 1534, 1281, 1341, 1035, 1313, 1165, 1127,  931,  799,  396,  374,  484,  887,
        1146, 1239, 1161, 1216, 1010, 1031, 1039,  971,  975, 1026, 1004, 1423, 1457, 1125,  966,
        1268,  849,  365,  925, 1114, 1000,  745,  319,  332,  700,  432,  388,  425,  586,  339,
         451,   56,  164,  571,  599,  492,  533,  612,  443,  270,  569,  176,  181,  175,  103,
          61,  133,   90,  464,  860,  242,  231,  320,  196,  696,   72,  246,  406,  497,  995,
         651,  408,  549,  165,  435,  297,  249,  278,  326,  506,  598,  526,  201,  337,  357,
         331,  897,  211,  229,  243,  244,  284,  265,  282,  641,  640,  570,  132,  476,  156,
         539,  262,  282,  130,  710, 1023,  272,  421,  512,  253,  383,  418,  691,  834, 1149,
        1226, 1136,  707,  492,  296,  430, 1120,  561,  545,  543,  627,  650,  576,  615,  443,
         408,  773,  579,  437,  708, 1188,  687,  462,  544, 1197, 1649,  258,  306,  205,  116,
         229,  420,  563,  890,  960,  867,  517,  385,   80,  163,  903,  290,  273,  271,  356,
         380,  305,  345,  330,  493,  541,  315,  228,  441,  946,  416,  190,  329,  929, 1381,
         512,  461,  290,  461,  410,  551,  945,  985,  879,  711,  633,  332,  220,  701,  351,
         330,  318,  371,  366,  319,  336,   92,  742,  368,  420,   75,  504, 1045,  415,  267,
         522,  843, 1382,  279,  224,   94,  378,  467,  666,  762,  691,  210,  189,  236,  300,
         990,  257,  262,  275,  323,  366,  314,  348,  601,  477,  638,  194,  450,  295,  680,
         365,  264,   35,  859, 1186,  251,  187,  558,  685,  941, 1031,  952,  459,  242,  150,
         340, 1098,  416,  406,  411,  492,  527,  453,  496,  525,  290,  733,  402,  433,  530,
         958,  549,  344,  313, 1072, 1457,  175,  318,  455,  774,  844,  753,  429,  353,  104,
          97,  853,  180,  165,  167,  251,  281,  206,  249,  378,  535,  488,  199,  233,  326,
         832,  311,   94,  237,  832, 1266,  412,  522,  754,  846,  770,  296,  179,  152,  267,
        1002,  275,  273,  283,  349,  390,  326,  366,  545,  415,  641,  236,  407,  357,  774,
         401,  244,  127,  914, 1271,  147,  537,  576,  472,  478,  567,  421,  263,  621,  142,
         153,  151,   67,   45,  115,   79,  492,  825,  298,  184,  338,  140,  653,   16,  230,
         358,  515,  982,  412,  435,  329,  509,  654,  556,  409,  606,  275,  290,  292,  207,
         191,  261,  226,  628,  936,  354,  286,  481,  173,  551,  148,  373,  439,  393,  835,
         126,  159,  559,  805,  853,  766,  917,  614,  635,  644,  576,  580,  630,  609, 1029,
        1120,  756,  575,  872,  454,  186,  531,  719,  631,  496,  525,  110,  674,  912,  931,
         823,  862,  674,  694,  700,  624,  620,  680,  653, 1063, 1226,  751,  647,  914,  519,
         292,  572,  779,  726,  410,  426,  630,  853,  844,  725,  767,  579,  598,  603,  524,
         517,  580,  550,  956, 1163,  641,  559,  809,  429,  344,  470,  683,  656,  337,  514,
         260,  445,  492, 1096,  402,  416,  431,  444,  484,  459,  481,  802,  571,  771,  322,
         644,  349,  523,  462,  448,  191,  871, 1082,  305,  447, 1173,  439,  441,  453,  509,
         552,  494,  532,  713,  315,  816,  383,  583,  481,  782,  553,  423,  215, 1044, 1330,
         190,  948,  281,  268,  271,  354,  386,  310,  353,  409,  439,  583,  285,  293,  416,
         896,  414,  198,  262,  936, 1356,  759,  151,  130,  123,  203,  221,  148,  186,  311,
         628,  394,  207,  151,  312,  845,  261,   50,  306,  767, 1238,  734,  732,  720,  669,
         625,  679,  642,  704, 1387,  365,  799,  688,  747, 1095,  636,  764,  974,  475, 1089,
          21,   34,   76,  115,   59,   92,  442,  684,  382,   80,  276,  161,  697,  133,  105,
         244,  656, 1093,   15,   86,  121,   53,   93,  421,  678,  376,   96,  256,  182,  718,
         146,   85,  252,  668, 1112,   85,  115,   43,   85,  408,  686,  364,  111,  243,  191,
         730,  145,   81,  266,  665, 1116,   43,   56,   41,  458,  760,  327,  130,  297,  139,
         676,   60,  166,  305,  581, 1036,   76,   35,  449,  799,  286,  173,  294,  164,  691,
          49,  191,  348,  551, 1026,   43,  407,  729,  324,  136,  244,  186,  726,  113,  115,
         302,  626, 1092,  421,  771,  293,  162,  263,  179,  714,   81,  157,  334,  585, 1060,
         796,  402,  512,  166,  593, 1133,  499,  359,  612,  896, 1453, 1022,  651,  721,  769,
        1093,  814,  627,  510, 1329, 1645,  455,  337,  437,  904,  313,  400,  626,  504, 1097,
         347,  131,  640,  170,  157,  175,  678, 1071,  430,  970,  343,  196,  457,  790, 1315,
         540,  125,  265,  266,  564,  941,  642,  796,  646,  682,  598,  225,  343,  523,  980,
         265,  742, 1197,  830, 1151,  625
    ];
    return n, dist

def ND(n, dist):
    N = range(n)
    D = [[None] * n for _ in xrange(n)]
    k = 0
    for i in xrange(n):
        for j in xrange(i + 1, n):
            D[i][j] = D[j][i] = dist[k]
            k += 1
    return N, D


if __name__ == '__main__':
    #N, D = ND(*gr())
    N, D = ND(*berlin())
    print N
    for Di in D:
        print Di
